package com.clarence.dada.core.base;

import com.clarence.dada.core.enums.ErrorEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 响应结果封装
 *
 * @author GD
 * @since 2020/10/17 17:33
 */
@Data
public class Result<T> {

    public static final Result<Void> SUCCESS = new Result<>(true,"成功");

    /**
     * 响应状态码
     **/
    @Schema(title = "响应状态码", example = "200")
    private String code;

    /**
     * 请求是否成功
     */
    @Schema(title = "请求是否成功", example = "true")
    private Boolean success;

    /**
     * 响应信息
     */
    @Schema(title = "响应信息", example = "成功")
    private String message;

    /**
     * 响应对象
     */
    @Schema(title = "响应对象", example = "T")
    private T data;


    public Result() {

    }

    public Result(ErrorEnum e) {
        this.success = false;
        this.message = e.getMessage();
        this.code = e.getCode();
    }

    public Result(T content) {
        this.data = content;
        this.code = "200";
        this.message = "成功";
        this.success = true;
    }

    public Result(String code, String message) {
        this.message = message;
        this.code = code;
        this.success = false;
    }

    public Result(Boolean success, String message) {
        this.message = message;
        this.success = success;
    }

    public Result(Boolean success, String code, String message) {
        this.message = message;
        this.code = code;
        this.success = success;
    }

    public Result(Boolean success, String code, String message, T content) {
        this.message = message;
        this.code = code;
        this.data = content;
        this.success = success;
    }
}


